import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class SRMCodingPhase
{
	public int countScore(int[] points, int[] skills, int lluck) {
		int pts = 0;
		for (int i = 1; i < (1 << 3); i++) {
			int tmp = 0;
			int luck = lluck;
			int min = 75;

			for (int j = 2; j >= 0; j--) {
				if ((i & (1 << j)) > 0) {
					if ((luck == 0 && min < skills[j])
							|| (luck != 0 && min < (luck >= skills[j] ? 1
									: skills[j] - luck)))
						break;

					tmp += points[j] - (1 << (j + 1)) * skills[j];
					min -= skills[j];
					if (luck > 0) {
						if (luck < skills[j]) {
							tmp += (1 << (j + 1)) * luck;
							min += luck;
							luck = 0;

						} else {
							tmp += (1 << (j + 1)) * (skills[j] - 1);
							luck -= skills[j] - 1;
							min += skills[j] - 1;
						}
					}
					// if(i==3)
					// System.out.println(min);
				}
			}
			pts = Math.max(pts, tmp);
		}
		return pts;
	}
	
	
}
//Powered by [KawigiEdit] 2.0!
